//
//  MainFirstTbv.m
//  ZITHER
//
//  Created by weixin on 2018/9/3.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "MainFirstTbv.h"
#import "CustomCameraVC.h"
#import "STViewController.h"

#import "MainBizQutoeCellText.h"
#import "MyEnquiryEndListNewModel.h"
#import "MyEnquiryListNewModel.h"

@implementation MainFirstTbv
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.delegate = self;
        self.dataSource = self;
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.rowHeight = UITableViewAutomaticDimension;
        self.showsHorizontalScrollIndicator = NO;
        self.showsVerticalScrollIndicator = NO;
        self.estimatedRowHeight = 100;
        
        [self registerNib:[UINib nibWithNibName:@"MainBizQutoeCell" bundle:nil] forCellReuseIdentifier:@"MainBizQutoeCell"];
        [self registerNib:[UINib nibWithNibName:@"MainBizQutoeCellText" bundle:nil] forCellReuseIdentifier:@"MainBizQutoeCellText"];

    }
    return self;
}


#pragma mark -- tabdelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    MyEnquiryListNewModel *model = self.arrMSource[0];
    NSArray *arr = self.arrMSource[1];
    return model.data.count + arr.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *sectionCell = @"MainBizQutoeCellText";
    MainBizQutoeCellText * cell = [[MainBizQutoeCellText alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    
    cell.index = indexPath.row;
    MyEnquiryListNewModel *model = self.arrMSource[0];
    NSArray *arr = self.arrMSource[1];
    if (indexPath.row<model.data.count) {
        //MyEnquiryListDataNewModel
        cell.modeTyep1 = model.data[indexPath.row];
    } else {
        //MyEnquiryListDataEndNewModel
        cell.modeTyep2 = arr[indexPath.row-model.data.count];
        
    }
    
    [cell setBlockChangeRefresh:^(NSInteger index) {
        if (self.blockChangeRefresh) {
            self.blockChangeRefresh(index);
        }
    }];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
    
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MyEnquiryListNewModel *model = self.arrMSource[0];
    STViewController *vc = [[STViewController alloc]init];
    vc.type = STControllerTypeHiddenNavBar;
    NSArray *arr = self.arrMSource[1];
    if (indexPath.row<model.data.count) {
        MyEnquiryListDataNewModel * model1 = model.data[indexPath.row];
        vc.goodId = model1.userEnquiryInfo.goodsId;
    } else {
        MyEnquiryListDataEndNewModel *model2 = arr[indexPath.row-model.data.count];
        vc.goodId = model2.goodsId;
    }
    [self.getNav pushViewController:vc animated:YES];
    
}



- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}




-(void)setIndex:(NSInteger)index
{
    _index = index;

}


-(NSMutableArray *)arrMSource{
    if (!_arrMSource) {
        _arrMSource = [[NSMutableArray alloc]init];
        for (int i =0; i<4; i++) {
            if (i==0) {
                [_arrMSource addObject:[[MyEnquiryListNewModel alloc]init] ];
            }else{
                [_arrMSource addObject:[[NSMutableArray alloc]init] ];
            }
        }
    }
    return _arrMSource;
}

-(void)setArrM:(NSMutableArray *)arrM
{
    _arrM = arrM;
    
    [self reloadData];
    
}
@end
